/*
 * Copyright (c) 2015 www.smarthome.com All rights reserved. 本软件源代码版权归----所有,未经许可不得任意复制与传播.
 */
package com.smarthome.base.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.smarthome.base.dao.ShSmsTempletDao;
import com.smarthome.base.dao.base.BaseDao;
import com.smarthome.base.service.ShSmsTempletService;
import com.smarthome.base.service.base.BaseServiceImpl;
import com.smarthome.domain.bean.ShSmsTemplet;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;

/**
 * ShSmsTempletService 实现类
 * 
 * @author KongXiangyu
 * @since 2015-09-07
 */
@Service("shSmsTempletService")
public class ShSmsTempletServiceImpl extends
		BaseServiceImpl<ShSmsTemplet, Long> implements ShSmsTempletService {

	@Resource
	private ShSmsTempletDao shSmsTempletDao;

	public BaseDao<ShSmsTemplet, Long> getDao() {
		return shSmsTempletDao;
	}

	@Override
	public DataGrid queryShSmsTemplates(PageHelper page,ShSmsTemplet query) {
		DataGrid dataGrid = new DataGrid();
		if(null == query) query = new ShSmsTemplet();
		long totalCount = shSmsTempletDao.selectEntryListCount(query);
		dataGrid.setTotal(totalCount);
		query.setOrderField("t.gmt_create");
		query.setOrderFieldType("desc");
		int startIndex = (page.getPage() - 1) * page.getRows();
		int endIndex = page.getPage() * page.getRows();
		query.setOrderField(page.getSort());
		query.setOrderFieldType(page.getOrder());
		if (totalCount > 0 && totalCount > startIndex) {
			query.setStartIndex(startIndex);
			query.setEndIndex(endIndex);
			List<ShSmsTemplet> shServices = shSmsTempletDao
					.selectTemplets(query);
			dataGrid.setRows(shServices);
		}
		return dataGrid;
	}
}